package com.hehao.reactorPractice;

import reactor.core.publisher.Flux;

import java.time.Duration;
import java.util.Arrays;

/**
 * @Author Damon
 * @Date 2024/5/7 16:22
 */
public class FluxCreateDemo {
    public static void main(String[] args) {
        System.out.println(fooBarFluxFromValues().subscribe());
    }

    // TODO Return an empty Flux
    static Flux<String> emptyFlux() {
        return Flux.empty();
    }

//========================================================================================

    // TODO Return a Flux that contains 2 values "foo" and "bar" without using an array or a collection
    static Flux<String> fooBarFluxFromValues() {
        return Flux.just("foo", "bar");
    }

//========================================================================================

    // TODO Create a Flux from a List that contains 2 values "foo" and "bar"
    static Flux<String> fooBarFluxFromList() {
       return Flux.fromIterable(Arrays.asList("foo", "bar"));
    }

//========================================================================================

    // TODO Create a Flux that emits an IllegalStateException
    static Flux<String> errorFlux() {
        return Flux.error(new IllegalStateException());
    }

//========================================================================================

    // TODO Create a Flux that emits increasing values from 0 to 9 each 100ms
    static Flux<Long> counter() {
        return Flux.interval(Duration.ofMillis(100)).take(10);
    }

}
